package aa;


import java.util.Random;

import org.junit.Test;

public class Testdemo {

    @Test
    public void test01() {
        // 创建 ElectricVehicles 子类对象的数组
        ElectricVehicles[] vehiclesArray = new ElectricVehicles[8];

        // 使用随机数据填充数组
        Random random = new Random();
        for (int i = 0; i < vehiclesArray.length; i++) {
            int a = i + 1;
            if (i < 2) {

                vehiclesArray[i] = new TwoWheeler("两轮电动车0" + a, "两轮编号0" + a
                        , Double.parseDouble(String.format("%.2f", random.nextDouble() * 100))
                        , "锂电池"
                        , Double.parseDouble(String.format("%.2f", random.nextDouble() * 300))
                        , random.nextInt(80)
                        , Double.parseDouble(String.format("%.2f", random.nextDouble() * 100000))
                        , "18寸"
                         , Double.parseDouble(String.format("%.2f", random.nextDouble() * 200)));
            } else if (i < 5) {
                vehiclesArray[i] = new ThreeWheeler("三轮电动车0" + a, "三轮编号0" + a
                        ,Double.parseDouble(String.format("%.2f", random.nextDouble() * 150))
                        , "铅酸"
                        , Double.parseDouble(String.format("%.2f", random.nextDouble() * 250))
                        , random.nextInt(70)
                        ,Double.parseDouble(String.format("%.2f", random.nextDouble() * 80000))
                        , random.nextInt(10) + 5
                        , random.nextBoolean());
            } else {
                vehiclesArray[i] = new TwoWheeler("两轮电动车0" + a, "两轮编号0" + a
                        , Double.parseDouble(String.format("%.2f", random.nextDouble() * 100))
                        , "锂电池"
                        , Double.parseDouble(String.format("%.2f", random.nextDouble() * 300))
                        , random.nextInt(80)
                        , Double.parseDouble(String.format("%.2f", random.nextDouble() * 100000))
                        , "18寸"
                        , Double.parseDouble(String.format("%.2f", random.nextDouble() * 200)));
            }
        }

        // 打印所有电动车信息
        System.out.println("所有电动车信息：");
        for (ElectricVehicles vehicle : vehiclesArray) {
            System.out.println(vehicle);
        }

        // 使用 equals 方法查找电动车
        ElectricVehicles searchVehicle = new TwoWheeler("两轮电动车01", "两轮编号01", 50.0,
                "锂电池", 150.0, 60, 70000.0, "18寸", 180.0);
        int foundIndex = -1;
        for (int i = 0; i < vehiclesArray.length; i++) {
            if (vehiclesArray[i].equals(searchVehicle)) {
                foundIndex = i;
                break;
            }
        }

        // 修改找到的电动车信息，并打印修改前后的信息
        if (foundIndex != -1) {
            System.out.println("\n找到匹配的电动车，索引为：" + foundIndex);
            System.out.println("修改前的信息：");
            System.out.println(vehiclesArray[foundIndex]);

            // 修改电动车信息
            vehiclesArray[foundIndex].setBatteryCapacity(55.0);
            vehiclesArray[foundIndex].setMaxRange(160.0);

            System.out.println("\n修改后的信息：");
            System.out.println(vehiclesArray[foundIndex]);
        } else {
            System.out.println("\n未找到匹配的电动车！");
        }

        // 调用充电接口的实现类方法
        ElectricVehicles ev = new TwoWheeler("TwoWheelerTest", "TW-T",
                60.0, "Lithium", 180.0, 70, 90000.0, "22寸", 200.0);
        ChargingInterface chargingInterface = new ChargingImpl();
        String chargingInfo = chargingInterface.charge(10);
        System.out.println("\n充电信息：" + chargingInfo);

        // 在找到的电动车后面插入新的电动车
        ElectricVehicles newVehicle = new ThreeWheeler("三轮电动车07", "三轮电动车01",
                80.0, "锂电池", 200.0, 60, 120000.0, 8, true);
        if (foundIndex != -1 && foundIndex < vehiclesArray.length - 1) {
            System.arraycopy(vehiclesArray, foundIndex, vehiclesArray, foundIndex + 1, vehiclesArray.length - 2 - foundIndex);
            vehiclesArray[foundIndex + 1] = newVehicle;
            System.out.println("\n插入新的电动车后的信息：");
            for (ElectricVehicles vehicle : vehiclesArray) {
                System.out.println(vehicle);
            }
        } else {
            System.out.println("\n无法在找到的电动车后插入新的电动车！");
        }
    }
}
